package com.example.medicine.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor implements HandlerInterceptor {
    /**
     * 请求到达控制器之前要执行的业务代码
     * 返回值为false,则执行请求的拦截.
     * 返回值为true,则表示不拦截请求,会向下调用后续的拦截器及控制器
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          Object currentUser=request.getSession().getAttribute("sessionUser");
      if(currentUser!=null){
          return true;
      }else {
          return false;
       }
    }

}
